$(document).ready(function() {
	/*
	 * // 任务附件的信息载体 function annexMsg() { this.tid = ""; this.filename = "";
	 * this.fileid = ""; }
	 * 
	 * var annexArray = new Array(); // 保存任务附件的数组
	 */
	$.ajax({
				type : "post",
				url : "/ag/lzw/taskTrack_queryTrackByPage.action",
				data : getParams(1),
				dataType : "JSON",
				success : showData,
				error : function(textStatus) {
					$("#loadingTrack").hide();
					$("#noneTrack").show();
					alert("Ajax请求失败，请检查本地的网络连接！");
					return false;
				}
			});

	// 分页查询，查第一页
	$("#firstPage").click(function() {
				doAjax(getParams(1));
			});
	// 分页查询，查上一页
	$("#prePage").click(function() {
				var pageCount = $("#pageCount").text();
				var page = $("#page").text();
				page = (parseInt(page) - 1);
				if (page <= 0) {
					alert("当前已是第一页！");
					return false;
				}
				doAjax(getParams(page));
			});
	// 分页查询，查下一页
	$("#nextPage").click(function() {
				var pageCount = $("#pageCount").text();
				var page = $("#page").text();
				page = (parseInt(page) + 1);
				if (page > pageCount) {
					alert("当前已是末页！");
					return false;
				}
				doAjax(getParams(page));
			});
	// 分页查询，查最后一页
	$("#lastPage").click(function() {
				var page = $("#pageCount").text();
				doAjax(getParams(page));
			});
	// 分页查询，跳转到第n页
	$("#jumpPage").click(function() {
				var pageCount = $("#pageCount").text();
				var page = $("#jump").val();
				if (page > pageCount) {
					alert("页数越界！");
					$("#pageCount").text(0);
					return false;
				}
				doAjax(getParams(page));
			});

	// 分页查询，异步提交
	function doAjax(d) {

		$.ajax({
					type : "post",
					url : "lzw/taskTrack_queryTrackByPage.action",
					data : d,
					dataType : "JSON",
					success : showData,
					error : function(textStatus) {
						$("#loadingTrack").hide();
						$("#noneTrack").show();
						alert("Ajax请求失败，请检查本地的网络连接！");
						return false;
					}

				});
	}

	function getParams(p) {

		$("#trackList").empty();
		$("#loadingTrack").show();
		var tid = $.cookie('tasktrackid');
		// tid = $.trim(tid);
		params = {
			"queryOption[\"tid\"]" : tid,// 从cookie中取出要查询的任务ID
			"queryOption[\"page\"]" : p
		};
		return params;
	}

	function showData(data) {
		$("#trackList").empty();
		var d = eval("(" + data + ")");
		if (d.trackList == null && d.errMsg != null) {
			$("#loadingTrack").hide();
			$("#noneTrack").show();
			$("#total").text(0);
			$("#page").text(0);
			$("#pageCount").text(0);

			// $.cookie('tracktask2', null);
		} else {

			$("#trackList").hide();
			$("#noneTrack").hide();
			$("#loadingTrack").hide();
			/*
			 * annexArray = null; annexArray = new Array(); // 更新附件数据的缓存
			 */
			$.each(d.trackList.list, function(i, n) {
						var tid = n.tfTime;
						/*
						 * $.each(n.annex, function(i, n) { // 遍历反馈信息中的附件信息 var
						 * trickAnnex = new annexMsg(); trickAnnex.tid = tid;
						 * trickAnnex.filename = n.filename; trickAnnex.fileid =
						 * n.fileid; annexArray.push(trickAnnex); //
						 * 使用JS数组annexArray，进行数据缓存 });
						 */
						fillHtml(n.fbid, n.tid, n.tfTime, n.tfText, n.tfPeople,
								n.tfCheck);
					});

			$("#total").text(d.trackList.total);
			$("#page").text(d.trackList.page);
			$("#pageCount").text(Math.ceil(d.trackList.total / 5));
			$("#trackList").show();
		}
	}

	function fillHtml(fbid, tid, time, text, people, check) {
		var fbcheck = "";
		if (check == 0) {
			fbcheck = "未审查";
		} else {
			fbcheck = "已审查";
		}

		var strHtml = "<tr>";

		strHtml += "<td height='20' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				+ fbid + "</div></td>";
		strHtml += "<td height='20' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				+ tid + "</div></td>";
		strHtml += "<td height='20' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				+ time + "</div></td>";
		strHtml += "<td height='20' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				+ people + "</div></td>";
		strHtml += "<td height='20' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				+ fbcheck + "</div></td>";
		strHtml += "<td height='20' bgcolor='#FFFFFF'><div align='center' class='STYLE1'>"
				+ "<input name='button' type='button' value='查看' id='"
				+ $.trim(fbid) + "' ></div></td>";
		strHtml += "</tr>";

		$("#trackList").append(strHtml);
        var ss = "#" + $.trim(fbid);
        
		//$(ss).unbind("click");
		$(ss).click(function() {
			var fbid = $(this).attr("id");
			$('#detailFrame').hide();
			$('#detailFrame', window.parent.document).attr("src","/ag/lzw/taskTrack_queryTrackDetail.action?feebackid="+fbid);
			$('#detailFrame').show();
		});

	}

});

				/*
				 * var strhtml = ""; $("#downList").empty();
				 * 
				 * $.each(annexArray, function(i, n) { //alert(n.tid);
				 * 
				 * if (n.tid == tid) { var fid = $.trim(n.fileid); strhtml += "<tr><td><a
				 * href='javascript:;'style='cursor: pointer;' class='fjdown'
				 * id='" + fid + "'>" + n.filename + "</a></td></tr>" var
				 * ffid = "#" + fid;
				 * 
				 * $('.fjdown').click(function() { alert(); $.ajax({ type :
				 * "post", url :
				 * "file/download.action?fileRealName="+$.trim(n.filename)+
				 * "&fileDiskURL="+ $.trim(n.fileid), error :
				 * function(textStatus) { alert("你要下载的文件不存！"); return false; }
				 * }); }); } }); $("#downList").append(strhtml);
				 * $("#AnnexDownloadWindow").dialog("open");
				 */
